package cn.kgc.tangcco.tcbd1011.no13.vehicle.action;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.kgc.tangcco.tcbd1011.no13.base.action.BaseServlet;
import cn.kgc.tangcco.tcbd1011.no13.base.properties.factory.PropertiesFactory;
import cn.kgc.tangcco.tcbd1011.no13.base.util.MyBeanUtils;
import cn.kgc.tangcco.tcbd1011.no13.base.util.Utils;
import cn.kgc.tangcco.tcbd1011.no13.vehicle.entity.Vehicle;
import cn.kgc.tangcco.tcbd1011.no13.vehicle.service.VehicleService;
import cn.kgc.tangcco.tcbd1011.no13.vehicle.vo.VehicleVo;
@WebServlet(name="VehicleServlet",urlPatterns="/vehicle.action")
public class VehicleServlet extends BaseServlet {
	private static final long serialVersionUID = 1L;
	private VehicleService vehicleService;
	public static final String SUCCESS = "vehicle.action?methodName=doListVehicle";
	public VehicleServlet() {
		vehicleService = (VehicleService) PropertiesFactory.getInstance(Utils.VEHICLESERVICE);
	}
	
	public String doListVehicle(HttpServletRequest request, HttpServletResponse response) {
		String forward = "vehicle/listVehicle";
		VehicleVo vehicle = new VehicleVo();
		request.setAttribute("vList", vehicleService.queryAllVehicle(vehicle));
		return forward;
	}
	public String toAddVehicle(HttpServletRequest request, HttpServletResponse response) {
		String forward = "vehicle/addVehicle";
		return forward;
	}
	public String doAddVehicle(HttpServletRequest request, HttpServletResponse response) {
		String forward = SUCCESS;
		request.setAttribute("add", vehicleService.addVehicle(MyBeanUtils.populate(Vehicle.class, request.getParameterMap())));
		return forward;
	}
	public String doDeleteVehicle(HttpServletRequest request, HttpServletResponse response) {
		String forward = SUCCESS;
		request.setAttribute("delete",vehicleService.deleteVehicle(Utils.parseInt(request.getParameter("vehicleId"))));
		return forward;
	}
	public String doDetailVehicle(HttpServletRequest request, HttpServletResponse response) {
		String forward = "vehicle/detailVehicle";
		request.setAttribute("vehicle", vehicleService.detailVehicle(Utils.parseInt(request.getParameter("vehicleId"))));
		return forward;
	}
	public String toUpdateVehicle(HttpServletRequest request, HttpServletResponse response) {
		String forward = "vehicle/updateVehicle";
		request.setAttribute("vehicle", vehicleService.detailVehicle(Utils.parseInt(request.getParameter("vehicleId"))));
		return forward;
	}
	public String doUpdateVehicle(HttpServletRequest request, HttpServletResponse response) {
		String forward = SUCCESS;
		request.setAttribute("update", vehicleService.updateVehicle(MyBeanUtils.populate(Vehicle.class, request.getParameterMap())));
		return forward;
	}
}
